package com.its.cloud.service.impl;

import com.its.cloud.dao.AccountMapper;
import com.its.cloud.service.AccountService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.concurrent.TimeUnit;

/**
 * @author huguangjun
 * @className AccountServiceImpl
 * @date 2021/1/18
 * @desc 11:14
 */
@Service
@Slf4j
public class AccountServiceImpl implements AccountService {
    @Resource
    private AccountMapper accountMapper;

    @Override
    public void decrease(Long userId, BigDecimal money) {
        log.error("seata-account-service中扣余额-start");
        // 模拟超时异常，全局事务回滚
//        try {
//            TimeUnit.SECONDS.sleep(20);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        accountMapper.decrease(userId,money);
        log.error("seata-account-service中扣余额-end");
    }
}
